local que_yibai = fk.CreateSkill {
    name = "que_yibai",
    anim_type = "control",
}
Fk:loadTranslationTable {
    ["que_yibai"] = "役白",
    [":que_yibai"] = "准备阶段，或当你受到伤害后(每回合限一次)，你可以摸X+1张牌，弃置Y张牌，若X与Y相等，则本次无需弃牌(X为体力值，Y为体力上限)。",

    ["#que_yibai-ask"] = "役白：是否摸 %arg 张牌，然后弃置 %arg2 张牌？",
    ["#que_yibai-drwa"] = "役白：是否摸 %arg 张牌？",
    ["@que_yibai"] = "役白",
}
local spec = {
    on_cost = function(self, event, target, player, data)
        local prompt
        if player:getMark("que_yifa") == 0 then
            if player.maxHp ~= player.hp then
                prompt = "#que_yibai-ask:::" .. player.hp + 1 .. ":" .. player.maxHp
            else
                prompt = "#que_yibai-drwa:::" .. player.hp + 1
            end
        else
            if player.maxHp ~= player.hp then
                prompt = "#que_yibai-ask:::" .. player.maxHp + 1 .. ":" .. player.hp
            else
                prompt = "#que_yibai-drwa:::" .. player.maxHp + 1
            end
        end
        return player.room:askToSkillInvoke(player,
            {
                skill_name = que_yibai.name,
                prompt = prompt
            })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local x
        local y
        if player:getMark("que_yifa") == 0 then
            x = player.hp
            y = player.maxHp
        else
            x = player.maxHp
            y = player.hp
        end
        player:drawCards(x + 1, que_yibai.name)
        if x ~= y then
            local cards = room:askToDiscard(player, {
                min_num = y,
                max_num = y,
                include_equip = true,
                skill_name = que_yibai.name,
                cancelable = false,
            })
            room:addPlayerMark(player, "@que_yibai", #cards)
        end
    end,
}

que_yibai:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(que_yibai.name) and target == player and player.phase == Player.Start
    end,
    on_cost = spec.on_cost,
    on_use = spec.on_use
})
que_yibai:addEffect(fk.Damaged, {
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(que_yibai.name) and target == player and
            player:getMark("que_yibai-turn") == 0
    end,
    on_cost = function(self, event, target, player, data)
        local prompt
        if player:getMark("que_yifa") == 0 then
            if player.maxHp ~= player.hp then
                prompt = "#que_yibai-ask:::" .. player.hp + 1 .. ":" .. player.maxHp
            else
                prompt = "#que_yibai-drwa:::" .. player.hp + 1
            end
        else
            if player.maxHp ~= player.hp then
                prompt = "#que_yibai-ask:::" .. player.maxHp + 1 .. ":" .. player.hp
            else
                prompt = "#que_yibai-drwa:::" .. player.maxHp + 1
            end
        end
        return player.room:askToSkillInvoke(player,
            {
                skill_name = que_yibai.name,
                prompt = prompt
            })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local x
        local y
        if player:getMark("que_yifa") == 0 then
            x = player.hp
            y = player.maxHp
        else
            x = player.maxHp
            y = player.hp
        end
        player:drawCards(x + 1, que_yibai.name)
        if x ~= y then
            local cards = room:askToDiscard(player, {
                min_num = y,
                max_num = y,
                include_equip = true,
                skill_name = que_yibai.name,
                cancelable = false,
            })
            room:addPlayerMark(player, "@que_yibai", #cards)
        end
        room:setPlayerMark(player, "que_yibai-turn", 1)
    end,
})

return que_yibai
